﻿@{
    ViewBag.Title = "产品列表";
    Layout = "~/Areas/Shared/_spEdit.cshtml";
   
}
@using Kaiser.Extensions
@model Kaiser.Modules.Hiner.Models.Product.ProductBase
<link href="@Url.Content("~/Scripts/Uploadify/3.1/uploadify.css")" rel="stylesheet"  type="text/css" />
<script src="@Url.Content("~/Scripts/Uploadify/3.1/swfobject.js")"   type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/Uploadify/3.1/jquery.uploadify-3.1.min.js")"   type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/Plugins/jquery-jtemplates.js")"   type="text/javascript"></script>
 
<script type="text/javascript">

    // extend the 'equals' rule
    $.extend($.fn.validatebox.defaults.rules, {
        validHdeCode: {
            validator: function (value, param) {

                var data0 = false;
                if (value.length >= param[0] && param[1] >= value.length) {
                    $.ajax({
                        type: "GET",
                        url: '@Url.Action("ValidHDECode", "ProductManage")',
                        dataType: "json",
                        data: { code: value, id: $("#ProductId").val() },
                        async: false,
                        success: function (data) {
                           
                            data0 = !(data == 1);
                        }
                    });
                } else {
                    param[2] = "请输入" + param[0] + "-" + param[1] + "位字符.";
                    return false;
                }

                param[2] = "HDECode已重复存在";
                return data0;



            },
            message: '{2}'
        },
        validHinerCode: {
            validator: function (value, param) {

                var data0 = false;
                if (value.length >= param[0] && param[1] >= value.length) {
                    $.ajax({
                        type: "GET",
                        url: '@Url.Action("ValidHinerCode", "ProductManage")',
                        dataType: "json",
                        data: { code: value, id: $("#ProductId").val() },
                        async: false,
                        success: function (data) {
                            //  alert(data)
                            data0 = !(data == 1);
                        }
                    });
                } else {
                    param[2] = "请输入" + param[0] + "-" + param[1] + "位字符.";
                    return false;
                }

                param[2] = "HinerCode已重复存在";
                return data0;



            },
            message: '{2}'
        }
    });

</script>
<form method="post">
    <div class="ftitle">BASE</div>
    <table>
        <tr>
            <td style="text-align: right; width: 120px">名称：
            </td>
            <td colspan="3">

                @Html.HiddenFor(m => Model.ProductId)
                @Html.TextBoxFor(m => Model.ProductName, new { @Class = "easyui-validatebox", @required = "true", @style = "width: 552px;" })
            </td>
        </tr>
        <tr>
            <td class="itemtxt" style="text-align: right">HDE Code：
            </td>
            <td>
                @*@Html.DropDownList()*@
                @Html.TextBoxFor(m => Model.ProductHDECode, new { @Class = "easyui-validatebox", @required = "true", @style = "width: 200px;", validType = "validHdeCode[6,16]" })
            </td>

            <td style="text-align: right">Hiner Code：
            </td>
            <td>
                @Html.TextBoxFor(m => Model.ProductHinerCode, new { @Class = "easyui-validatebox", @required = "true", @style = "width: 200px;", validType = "validHinerCode[6,16]" })
            </td>
        </tr>
        <tr>
            <td style="text-align: right">OE Ref：
            </td>
            <td>
                @Html.TextBoxFor(m => Model.ProductOERef, new { @Class = "easyui-validatebox", @required = "true", @style = "width: 200px;", @maxlength = "10" })
            </td>

            <td style="text-align: right">Car Model：
            </td>
            <td>
                @Html.TextBoxFor(m => Model.ProductCarModel, new { @Class = "easyui-validatebox", @required = "true", @style = "width: 200px;", @maxlength = "10" })
            </td>
        </tr>
        <tr>
            <td style="text-align: right">供应商：
            </td>
            <td>
                <input id="selectSupplier" style="width: 205px" />
                @Html.HiddenFor(m => Model.SupplierCode)
                @Html.HiddenFor(m => Model.SupplierName)
            </td>
            <td style="text-align: right">价格：
            </td>
            <td>
                @Html.TextBoxFor(m => Model.ProductPrice, new { @Class = "easyui-numberbox", @style = "width: 200px;", @maxlength = "10" })
            </td>
        </tr>

        <tr>
            <td style="text-align: right">Inner Package Size：
            </td>
            <td>
                @Html.TextBoxFor(m => Model.InnerPackageSize, new { @Class = "easyui-validatebox", @required = "true", @style = "width: 200px;", @maxlength = "10" })
            </td>

            <td style="text-align: right">Outer Package Size：
            </td>
            <td>
                @Html.TextBoxFor(m => Model.OuterPackageSize, new { @Class = "easyui-validatebox", @required = "true", @style = "width: 200px;", @maxlength = "10" })
            </td>
        </tr>
        <tr>
            <td style="text-align: right">备注：
            </td>
            <td colspan="3">
                @Html.TextAreaFor(m => Model.ProductDesc, new { @Class = "easyui-validatebox", @required = "true" })
            </td>
        </tr>
        <tr>
            <td style="text-align: right">产品描述：
            </td>
            <td colspan="3">
                @Html.TextAreaFor(m => Model.ProductDepict, new { @Class = "easyui-validatebox", @required = "true" })
            </td>
        </tr>


    </table>
    <div class="ftitle">PACKING</div>
    <div>
        <div style="float: left;">


            <div>Inner Package Img</div>
            <div style="margin-top: 2px">
                @Html.HiddenFor(m => Model.InnerPackageImgUrl, new { @Class = "attach" })
                @Html.HiddenFor(m => Model.InnerPackageImgName)
            </div>
        </div>
        <div style="float: left; margin-left: 8px">

            <div>Outer Package Img</div>
            <div style="margin-top: 2px">
                @Html.HiddenFor(m => Model.OuterPackageImgUrl, new { @Class = "attach" })
                @Html.HiddenFor(m => Model.OuterPackageImgName)
            </div>
        </div>
        <div style="float: left; margin-left: 8px">

            <div style="text-align: center">Lable</div>
            <div style="margin-top: 2px">
                @Html.HiddenFor(m => Model.LabelImgUrl, new { @Class = "attach" })
            </div>
        </div>
          <div style="float: left; margin-left: 8px">

            <div style="text-align: center">Product</div>
            <div style="margin-top: 2px">
                @Html.HiddenFor(m => Model.ProductImgUrl, new { @Class = "attach" })
            </div>
        </div>
        <div id="some_file_queue" class="some_file_queue" style="margin-left: 4px;float: left"> 
            
        </div>
    </div>
    <div style="clear: left"></div>
    <div class="ftitle">PRODUCT SHOW</div>
    <div id="addPic"   class="attachList">
        @(new HtmlString(Model.PhotoList.ToJson()))
    </div>
    <div id="some_file_queue2" class="some_file_queue">
        
    </div>

</form>
<script type="text/javascript">
    $(document).ready(function () {
        var g = $('#selectSupplier').combobox({
            panelWidth: 500,
            url: '@Url.Action("GetSupplierList", "SupplierManage", new { area = "Hiner" })',
            valueField: 'SupplierCode',
            textField: 'SupplierName',
            mode: 'remote',
            multiple: true,

            onSelect: function () {

                $("#SupplierCode").val($('#selectSupplier').combobox('getValues'));
                $("#SupplierName").val($('#selectSupplier').combobox('getText'));

            },
            panelHeight: 'auto'
        });

        g.combobox("setValues", $("#SupplierCode").val().split(','));

        $(".attachList").each(function () {

          
            
            var o = $(this);
            var oid = o.attr("id");
            var oVal = o.text();
  
            var arr = $.parseJSON(oVal);
            var photoContern = $("<div id='" + oid + "_photoContern'></div>");
            o.after(photoContern);
            o.uploadify({
                'formData': { "ObjectID": $("#ProductId").val(), "ObjectModule": "HinnerProductPhoto" },
                'swf': '@Url.Content("~/Scripts/Uploadify/3.1/uploadify.swf")',
                'uploader': '@Url.Action("UploadFiles", "ProductManage", new { area = "Hiner" })',
                'queueID': 'some_file_queue2',
                "buttonText": "点击添加",
                'buttonCursor': 'arrow',
                onInit: function (instance) {
                    var obj = $("#" + instance.settings.id);

                    if (arr && arr.length > 0) {
                        for (var i = 0; i < arr.length; i++) {
                            var photo = arr[i];
                    
                                photoContern.append('<img width=120 height=88   style="border: 1px solid #95b8e7; margin-right: 8px" src="' + photo.SourceUrl + '" />');
                           
                            
                        }
                    }

                },
                onUploadSuccess: function (a, b) {
                    var result = $.parseJSON(b);
                    if (result.msg != "" && result.msg != undefined) {
                        alert(result.msg);
                    } else {
                      
                            photoContern.append('<img width=120 height=88   style="border: 1px solid #95b8e7; margin-right: 8px" src="' + result.Data.FilePath + '" />');
                      
                    }
                    //photoContern.find("")
                }
            });            

        });


        $(".attach").each(function () {
           
            var o = $(this);
            var oid = o.attr("id");
            var attach = $('<div id="' + oid + '_attach"><div>');
            o.after(attach);
            attach.uploadify({
                'formData': { "ObjectID": $("#ProductId").val(), "ObjectModule": "HinnerProduct" },
                'swf': '@Url.Content("~/Scripts/Uploadify/3.1/uploadify.swf")',
                'uploader': '@Url.Action("UploadFiles", "ProductManage", new { area = "Hiner" })',
                'buttonImage': '@Url.Content("~/Themes/images/Snap1.jpg")',
                height: 88,
                'queueID': 'some_file_queue',
                'buttonCursor': 'arrow',
                "buttonText": "点我上传",
                onInit: function (instance) {
                    var obj = $("#" + instance.settings.id);

                    if (o.val() != '') {
                        obj.find(".uploadify-button").hide();
                        obj.find("img").remove();
                        obj.append('<img width=120 height=88  style="border: 1px solid #95b8e7" src="' + o.val() + '" />');

                    }

                },
                onUploadSuccess: function (a, b) {
                    var result = $.parseJSON(b);
                    if (result.msg != "" && result.msg != undefined) {
                        alert(result.msg);
                    } else {
                        var obj = $(this.wrapper[0]);
                        obj.find(".uploadify-button").hide();
                        obj.find("img").remove();
                        obj.append('<img width=120 height=88  style="border: 1px solid #95b8e7" src="' + result.Data.FilePath + '" />');
                        o.val(result.Data.FilePath);
                        // var o = $(this.wrapper[0], "img").attr('src', result.Data.FilePath);
                        //   $("#fileToUpload222-button").html("background-image", "url('" + result.Data.FilePath + "')").before("<img width=80 height=80 src='" + result.Data.FilePath + "' />");

                    }
                }
            });

        });

    });
</script>


